from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2

# 创建对象的基类
Base = declarative_base()

# 生成结果历史类
class BankScore(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_GSQYPJB'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    GSMC = Column(VARCHAR2(128))
    ZF = Column(VARCHAR2(16))  # 评分
    PJ = Column(VARCHAR2(16))  # 评级
    @classmethod
    def from_dict(cls, data):
        return cls(
            ID      = int(data.get('ID')) if data.get('ID') is not None else 0,
            GSMC = data.get('GSMC'),
            ZF = data.get('ZF'),
            PJ = data.get('PJ')
        )

    def to_all_dict(self):
        return {
            'ID'  : self.ID,
            'GSMC' : self.GSMC,
            'ZF' : self.ZF,
            'PJ' : self.PJ
        }
    def to_dict(self):
        return {
            'ID':       self.ID,
            'GSMC': self.GSMC,
            'ZF': self.ZF,
            'PJ': self.PJ
        }

